import { httpGet, httpPost } from "@/utils/req";
import type { CommentData } from "./type";

// 获取附近推荐数据
export const getRecommendAPI = async (
  location: object,
  distance: number = 5
) => {
  try {
    const data = await httpGet("/getIndexData", {}, { location, distance });
    // console.log("请求成功，获取的数据为：", data);
    return data; // 这里现在可以返回请求到的数据
  } catch (error) {
    console.error("请求失败", error);
    return undefined; // 发生错误时返回 undefined
  }
};

// 获取热点数据
export const getHotDataAPI = async (page: number, size: number) => {
  try {
    const data = await httpGet("/getHotData", {}, { page, size });
    // console.log("请求成功，获取的数据为：", data);
    return data; // 这里现在可以返回请求到的数据
  } catch (error) {
    console.error("请求失败", error);
    return undefined; // 发生错误时返回 undefined
  }
};

// 获取详情数据
export const getDetailDataAPI = async (id: number, type: string) => {
  try {
    const data = await httpGet("/getDetail", {}, { id, type });
    // console.log("请求成功，获取的数据为：", data);
    return data; // 这里现在可以返回请求到的数据
  } catch (error) {
    console.error("请求失败", error);
    return undefined; // 发生错误时返回 undefined
  }
};

// 获取评论数据
export const getCommentDataAPI = async (params: CommentData) => {
  try {
    const { page, limit, userId, type, typeId } = params;
    const data = await httpGet(
      "/getCommentData",
      {},
      { page, limit, userId, type, typeId }
    );
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};

// 获取分类总览的数据
export const getCategoryDataAPI = async (
  type: string,
  location: string,
  limit: number,
  page: number
) => {
  try {
    const data = await httpGet(
      "/getListData",
      {},
      { type, location, limit, page }
    );
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};

// 获取地图数据
export const getMapDataAPI = async (
  location: object,
  type: string,
  distance: number
) => {
  try {
    const data = await httpGet("/getMapData", {}, { location, type, distance });
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};

// 登录接口
export const loginAPI = async (paramas: object) => {
  try {
    // const data = await httpPost("/loginUser", {}, paramas);
    const data = await httpPost("/login", {}, paramas);

    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
// 获取用户信息
export const getUserInfoAPI = async (userId: string) => {
  try {
    const data = await httpGet("/getUserInfo", {}, { userId });
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
// 修改用户信息
export const updateUserInfo = async (params: any) => {
  try {
    const data = await httpPost("/updateUserInfo", {}, params);
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
// 获取反馈信息
export const getFeedbackAPI = async (params: any) => {
  try {
    const data = await httpGet("/getFeedback", {}, { params });
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
// 添加反馈信息
export const addFeedbackAPI = async (params: any) => {
  try {
    const data = await httpPost("/addFeedback", {}, { params });
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
// 获取对应用户评论
export const getUserCommentAPI = async (params: any) => {
  try {
    const data = await httpGet("/getUserComment", {}, { params });
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
// 添加对应评论
export const addCommentAPI = async (params: any) => {
  try {
    const data = await httpPost("/addComment", {}, { params });
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
//添加回复评论
export const addRecoverCommentAPI = async (params: any) => {
  try {
    const data = await httpPost("/addRecoverComment", {}, params);
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
// 获取收藏数据
export const getCollectDataAPI = async (params: any) => {
  try {
    const data = await httpGet("/getFavoriteData", {}, { params });
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
// 判断是否收藏
export const getHasFavAPI = async (params: any) => {
  try {
    const data = await httpGet("/getHasFav", {}, params);
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
// 添加收藏数据
export const addCollectDataAPI = async (params: any) => {
  try {
    const data = await httpPost("/addFavorite", {}, params);
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
// 删除收藏数据
export const removeCollectDataAPI = async (params: any) => {
  try {
    const data = await httpPost("/removeFavorite", {}, params);
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};

// 推荐数据
export const recommendDataAPI = async (params: any) => {
  try {
    const data = await httpPost("/recommendData", {}, params);
    return data;
  } catch (error) {
    console.error("请求失败", error);
    return undefined;
  }
};
